import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import javax.xml.bind.Element;
import java.util.List;

import static java.lang.Thread.sleep;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com");
        WebElement element =  webDriver.findElement(By.cssSelector(".s_ipt"));

        element.sendKeys("软件测试");
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(2000);

        List<WebElement> elements = webDriver.findElements(By.cssSelector("a em"));

        for (int i = 0; i < elements.size(); i++) {
            //System.out.println(elements.get(i).getText());
            if (!elements.get(i).getText().contains("软件")||!elements.get(i).getText().contains("测试")){
                System.out.println(elements.get(i).getText());
                System.out.println("测试失败");
            } else  {
                System.out.println("测试通过");
            }
        }

    }
}
